package com.siwei.mes.entity.materials;

import cn.dev33.satoken.stp.StpUtil;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import com.siwei.mes.config.UidUtils;
import com.siwei.mes.enums.GenerateCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;


/**
 * 试验说明表(MaterialsTestProjectDesc)实体类
 *
 * @author linzi
 * @since 2024-05-18 23:25:58
 */
@Data
@Accessors(chain = true)
@Table(name = "pk_materials_test_project_desc")
@ApiModel(value = "MaterialsTestProjectDesc", description = "试验说明表")
public class MaterialsTestProjectDesc implements Serializable {
    private static final long serialVersionUID = 219267998512162044L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "试验说明表主键ID", name = "id")
    @NotNull(message = "主键id为空")
    private Long id;

    @ApiModelProperty(value = "说明编号")
    private String descNo;

    /**
     * 类型  字典 MATERIAL_TYPE
     */
    @Column(name = "material_type")
    @ApiModelProperty(value = "类型  字典 MATERIAL_TYPE", name = "materialType")
    @NotNull(groups = {AddGroup.class, UpdateGroup.class}, message = "类型为空")
    private Long materialType;
    /**
     * 类型 字典名称
     */
    @Column(name = "material_type_name")
    @ApiModelProperty(value = "类型 字典名称", name = "materialTypeName")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "类型名称为空")
    private String materialTypeName;
    /**
     * 试验项目编码   materials_test_project 表的item_code
     */
    @Column(name = "item_code")
    @ApiModelProperty(value = "试验项目编码", name = "itemCode")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "试验项目编码为空")
    private String itemCode;
    /**
     * 试验项目名称   materials_test_project 表的item_name
     */
    @Column(name = "item_name")
    @ApiModelProperty(value = "试验项目名称", name = "itemName")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "试验项目名称为空")
    private String itemName;
    /**
     * 国标
     */
    @Column(name = "national_standard")
    @ApiModelProperty(value = "国标", name = "nationalStandard")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "国标为空")
    private String nationalStandard;
    /**
     * 地标
     */
    @Column(name = "landmark")
    @ApiModelProperty(value = "地标", name = "landmark")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "地址为空")
    private String landmark;
    /**
     * 实验室管理
     */
    @Column(name = "laboratory_manage")
    @ApiModelProperty(value = "实验室管理", name = "laboratoryManage")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "实验室管理为空")
    private String laboratoryManage;
    /**
     * 创建人
     */
    @Column(name = "creater")
    @ApiModelProperty(value = "创建人", name = "creater")
    private Long creater;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;
    /**
     * 修改人
     */
    @Column(name = "updater")
    @ApiModelProperty(value = "修改人", name = "updater")
    private Long updater;
    /**
     * 更新时间
     */
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间", name = "updateTime")
    private Date updateTime;
    /**
     * 是否删除  1-删除
     */
    @Column(name = "is_del")
    @ApiModelProperty(value = "是否删除  1-删除", name = "isDel")
    private Integer isDel;

    public MaterialsTestProjectDesc init(boolean isCreate) {
        this.setUpdater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                .setUpdateTime(new Date());
        if (isCreate) {
            this.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                    .setCreateTime(new Date()).setIsDel(0)
                    .setDescNo(UidUtils.genNo(GenerateCodeEnum.EXPERIMENT_DESC.getCode()));
        }
        return this;
    }
}
